package com.hdaccp.hadoop.mr2;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Objects;

public class TwoNum implements WritableComparable<TwoNum>{

    private long firstNum ;
    private  long seondNum ;

    public TwoNum(){
        super() ;
    }

    public TwoNum(long firstNum,long seondNum){
        this.firstNum = firstNum ;
        this.seondNum = seondNum ;
    }

    public long getFirstNum() {
        return firstNum;
    }

    public void setFirstNum(long firstNum) {
        this.firstNum = firstNum;
    }

    public long getSeondNum() {
        return seondNum;
    }

    public void setSeondNum(long seondNum) {
        this.seondNum = seondNum;
    }

    /**
     *
     * @param o
     * @return
     */

    @Override
    public int compareTo(TwoNum o) {
        final long minus = this.firstNum - o.firstNum;
        if (minus != 0) {
            return (int) -minus;
        }
        return (int) -(this.seondNum - o.seondNum);






    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
            dataOutput.writeLong(firstNum);
            dataOutput.writeLong(seondNum);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.firstNum = dataInput.readLong() ;
        this.seondNum = dataInput.readLong() ;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TwoNum twoNum = (TwoNum) o;
        return firstNum == twoNum.firstNum &&
                seondNum == twoNum.seondNum;
    }

    @Override
    public int hashCode() {

        return Objects.hash(firstNum, seondNum);
    }
}
